-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error handling in pure runtimes #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks promising. I don't quite see how this PR addresses the laziness fix you described in point №2, can you please spell that out for me? I would've expected to see some kind of force
-ish function call in runtimeLoop
.
Can you please also add a changelog entry?
There was no
I'll. |
Sorry for a slow response to this one, I was traveling and then came back to quite a bit. This does look pretty appealing! You're right that it seems quite odd to include Before the final go-ahead, I'm curious to discuss if this behavioral change would be noticeable to any possible consumers. If anyone was attempting to parse the error from their logs, their parsers would break. If there was anyone that consistently saw errors in a pure runtime, they might now see a performance hit as their containers get trashed and restarted vs reused. And I suppose, it is maybe worth considering that for pure runtimes, re-use may be preferable, just by virtue of being pure, so the container should still be in a valid state to keep processing new requests. Handling invalid JSON is definitely seems like a net improvement. If any of these did seem like it could affect consumers, we could consider a breaking change, which could released right away for a case like this. Curious to hear everyone's perspectives here. |
We've only ever used |
This is a breaking change. The output of the lambda function was wrapped in
If they prefer not reporting errors to AWS, they can use |
Hi @IamfromSpace, is there anything we can do to unstick this? |
Hey, absolutely, sorry I’ve been swamped as of late. But I can dedicate tomorrow to getting this out, and it’s well over due! My plan is to flip the Aeson flag to false, and release another 1.0 in a way that’s seamless for the current stack LTS, but lets cabal and other users opt in easily. Then we’ll put this on top as a 1.1, with that flag set to true, so we’re in a good spot for the next LTS release. Let me know if there’s any concerns with this plan, otherwise I’ll stick to it! |
You might not need the flag any more. There's now an empty release of the compat package https://hackage.haskell.org/package/attoparsec-aeson-2.1.0.0 which depends on |
And thank you for coming back to look at this, especially so close to the end of the year. |
Yeah, this absolutely works as an alternate approach, and it's what was implemented first. Ultimately, in trying the flag based approach, I just liked the result better than using the compatibility package. It over all seemed like more things "just worked" via this route. Long term, I also think flags may be a good way to handle both back porting changes while allowing trunk-based development. At some point I'll experiment more with this, where the current code base actually serves all current major releases, but flags set the correct interfaces or behaviors across them. Ultimately, I think flags just seemed like the more flexible and sustainable pattern. Next time something like this happens, there's no need to wait on compatibility package release! |
Okay, hey all, I've got the main blocker out of the way, and I've spent a good while making sure I really understand what's going with this change. I still want to tinker a bit more, and I'm going to prioritize getting this closed out over the next couple days. So far my thinking on this has two angles:
My feeling is that these two things should be separated. Since they both introduce a break, it might be worthwhile to try to release them at the same time though. tl;dr: I think fallible runtime shouldn't be wrapped in an Either, but that it should crash--unless none of the runtimes crash. Any additional thoughts or consideration folks want to throw out here? |
I'll create another PR. |
Okay awesome. I think we can get the fallible changes through right away if you just want to update this one to just do that. |
Okay, I think I finally get it; sorry, I feel like I've been a bit dense on this one! I was mixing up errors, crashing the runtime, and container discarding. If an error is reported without exit, the process is reused. If the process exits, the process is restarted. In both cases the container is reused, and there's simply no way to force it to be discarded (to prevent use of an undefined or corrupted environment). Personally, I think safer options (discarding the container and/or restarting the process) are better, but that's simply not how lambda containers work. They prioritize speed, and know that most applications simply won't corrupt the environment--and if you make your lambdas stateful, then you just have to be careful. So, I totally agree then, fallible and pure runtimes should not crash the runtime environment--which is consistent with the other runtimes that parse. They don't crash, they simply report the error and keep on running. Which, for parsing, is definitely preferred anyway, we know the environment is fine to re-use. Also agreed that we want to eliminate the possibility of laziness here for the parsing error all together. Good catch on how that interplay works. I'm going to play with this PR as is, but I'm leaning towards now it just being the right approach. Sorry for the back and forth, I just really want to make sure I've understood the complete picture! |
Appreciate the patience on this one. At this point, once the merge conflict is resolved, this one is good to go for me. |
Thanks, if there is no need to split this into two PRs.
|
Yeah, no need. I originally just wanted to make sure that we were getting resolved stuff through while giving more time for discussion to open topics. But since these are ready and reasonably related, I think we're better off just going for it. |
This went out yesterday as 1.1 🎉 Thanks much for this, this is a definite improvement. I’d also like to explore longer term approaches for wringing out laziness so that these kinds of things can’t manifest in user code either. We don’t want things to be lazy across executions. I’ll open an issue on the topic. |
There were two problems with pure runtimes:
Left
fromfallibleRuntime
,Left
appears literally in the response, and the lambda function exit successfullywithInfalllibleParse
crashes runtime on parse failure #108Screenshot for the two problems, respectively:
Reasons for these problems:
Either
infalliableRuntimeWithContext
Either String result
wasn't handled, and it was treated as aToJSON
value as a whole.withInfallibleParse fn = either error fn . parseEither parseJSON
, theLeft
side ofEither
was thrown byerror
in a pure context. When we later calltry
, the value is still lazy and possibly not evaluated.This PR addresses both problems.